import SimpleSchema from 'simpl-schema';
import { Schemas } from './Schemas';
import { Random } from 'meteor/random';

Schemas.Notification = new SimpleSchema({
  _id: {
    type: String,
    autoValue: function () {
      if (this.isInsert) {
        return Random.id();
      }
    }
  },
  type: {
    type: String,
    allowedValues: [
      // 用户申请加入频道[成功]
      'UserJoinChannel',
      'UserJoinChannelSuccess',
      // 用户申请加好友[成功]
      'UserMakeFriend',
      'UserMakeFriendSuccess',
      // 系统通知
      'SystemNotification',
      // 用户邀请
      'invite.user.join.channel'
    ]
  },
  user_id: {
    type: String
  },
  details: {
    type: Object,
    blackbox: true
  },
  read: {
    type: Boolean,
    autoValue: function () {
      if (this.isInsert) {
        return false;
      }
    }
  },
  createdAt: {
    type: Date,
    autoValue: function () {
      if (this.isInsert) {
        return new Date();
      } else if (this.isUpsert) {
        return { $setOnInsert: new Date() };
      } else {
        this.unset();
      }
    }
  }
});
